package threading;

public class ThreadDemo10 {
    public static void main(String[] args)  {
        Thread t = new Thread(()->{
            //currentThread()是获取到当前线程的实例
            //此处currentThread得到的对象就是t
            //isInterrupted()可以理解为t对象里自带的一个标志位
            while(!Thread.currentThread().isInterrupted()) {
                System.out.println("hello t");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    //break;
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                    }
                }

            }
        });


        t.start();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //把t内部的标志位给设置成true
        t.interrupt();
    }


}
